#include <iostream>
#include <algorithm>
#include <cstring>

using namespace std;

const int MAXN = 105;
const int MAXM = 10005;

struct Edge {
    int u, v, w;
} e[MAXM];

int f[MAXN];

bool cmp(Edge a, Edge b) {
    return a.w < b.w;
}

int find(int x) {
    if (f[x] == x) return x;
    return f[x] = find(f[x]);
}

int main() {
    int c, n, m;
    while (cin >> c >> n >> m) {
        if (c == 0 && n == 0 && m == 0) break;
        for (int i = 1; i <= m; i++) {
            cin >> e[i].u >> e[i].v >> e[i].w;
        }
        sort(e + 1, e + m + 1, cmp);
        for (int i = 1; i <= n; i++) {
            f[i] = i;
        }
        int ans = 0, cnt = 0;
        for (int i = 1; i <= m; i++) {
            int u = e[i].u, v = e[i].v, w = e[i].w;
            int fu = find(u), fv = find(v);
            if (fu != fv) {
                f[fu] = fv;
                ans += w;
                cnt++;
            }
            if (cnt == n - 1) break;
        }
        if (ans <= c) {
            cout << "Yes" << endl;
        } else {
            cout << "No" << endl;
        }
    }
    return 0;
}